/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
// Engine.h: interface for the CEngine class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ENGINE_H__273FFF1E_D2B4_40D4_928D_E121ED833341__INCLUDED_)
#define AFX_ENGINE_H__273FFF1E_D2B4_40D4_928D_E121ED833341__INCLUDED_

//#include "ssi_Output.h"	// Added by ClassView
//#include "ssi_StdOutput.h"
//#include "ssi_ErrorOutput.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ssi_interpreter.h"
#include "ssi_status.h"	// Added by ClassView
#include "ssi_variable.h"
#include "ssi_function.h"

#include "ssi_tnode.h"
#include "ssi_statement.h"
#include "ssi_functiondecl.h"
#include "ssi_string.h"	// Added by ClassView
#include "ssi_ghostclass.h"
#include "ssi_classdecl.h"
#include "ssi_functionset.h"
#include "ssi_keyworddecl.h"
#include "ssi_environment.h"

class CInterpreter;
class SSI_SCRIPTDLL_API CEngine : public GhostClass
{
public:

	virtual void SSI_FunctionProcessor(SSI_FunctionAPI& theAPI);

	virtual SSI_BOOL GetVariable(CVariable &Var, SSI_BOOL bLocalOnly = 0);
	virtual CEngine* CreateFunctionEngine();
	void disp(CData* InData);
	CStatus compare(COperator& anOp);
	SSI_INT64* getidentity(SSI_INT64& Size);
	String getstring();
	CStatus DoOperator(COperator &anOp);
	
	CStatus FindFunctionDecl(CFunctionDecl &aFunc);
	CStatus AddFunction(CFunctionDecl &aFunc);
	
	CStatus FindClassDecl(CClassDecl &aClass);
	CStatus AddClass(CClassDecl aClass);
	
	CStatus SetVariable(CVariable& aVar);
	CStatus SetVariable(VarTree &VarSet, CVariable &InVar);
	CStatus Evaluate(CStatement& aStat);
	virtual SSI_BOOL IsFunction(const String& fName);
	CStatus DoFunction(CFunction &aFunc);
	
	//void SetIO(COutput anOut, COutput anErr, COutput anIn);
	
	CStatus AddNewVariable(SSI_INT64 Type, const String& Name, String InitialValue = "");
  CStatus AddVariable(CVariable newVar);
	CStatus CopyVariable(CVariable& inVar, const String& newName);
  SSI_BOOL CheckName(const String& sName);

	void SetInterpreter(CInterpreter* Interp);
	CEngine(SSI_BOOL bAddLocalFunctions = 1);
	virtual ~CEngine();
protected:
	virtual void SetParent(CEngine* Par);

private:
	virtual CStatus subtract(COperator &anOp);
	virtual CStatus divide(COperator &anOp);
	virtual CStatus power(COperator &anOp);
	virtual CStatus multiply(COperator &anOp);
  virtual CStatus modulous(COperator &anOp);
  virtual CStatus bit_and(COperator &anOp);
  virtual CStatus bit_or(COperator &anOp);
  virtual CStatus log_and(COperator &anOp);
  virtual CStatus log_or(COperator &anOp);
	virtual CStatus plus(COperator &anOp);
  virtual CStatus equal(COperator &Eq);
	SSI_INT64 testadd(SSI_INT64 i1, SSI_INT64 i2);
	void print(const SSI_CHAR* S);
	SSI_INT64 test();
	virtual void who(CEngine* In, SSI_BOOL bLabel = 1);
 
	typedef TNodeTree<CClassDecl> ClassTree;
  typedef TNode<CClassDecl> ClassNode;

protected:
	//CErrorOutput err;
	
	CEngine* parEngine;

	ssi_stream* out;
  File* log;
	VarTree Vars;
	KeyTree Keys;
	CFunctionSet* FuncSet;
	ClassTree Classes;

  CStatus RetStat;
  String RetMess;
	
	CInterpreter* Interpreter;

  SSI_BOOL IsLoopEngine;
 
public:
	void SetOutDisplay(ssi_stream* NewDisp);
	CInterpreter* GetInterpreter(void);
	CDataClass* CallingClass;
	void what(void);
	void what(String& Package);
	void whatHELP(String& Package, String& FileName);
	CStatus ProcessInternalFunction(CFunction& aFunc, CFunctionDecl& aDecl);
	CStatus AddKeyword(CKeywordDecl& aKey);
	CStatus DoKeyword(CKeywordDecl& aKey, String& InData);
	CStatus AddVariable(CData& InData, String& Name);
	ssi_stream* GetOutStream(void);
	CStatus SetPackageName(const char* Name);
	CStatus increment(COperator& anOp);
	CStatus decrement(COperator& anOp);
	String UserPackageName;
  CEnvironment* Environment;
  void ClearVariables(void);
  void RemoveVariable(CVariable& Var);
  void RemoveFunction(String& Name);
  void ClearFunctions(void);
  //int StartLog(String& FileName);
  CStatus Log(String& Message);
  void SetLoopEngine(void);

  virtual String GetPackageContents(const String& PackDelim, const String& FuncDelim);
  virtual String GetVariableTypes(const String& Delim);
  virtual String GetAllVariableMembers(const String& VarDelim, const String& FuncDelim);
  CStatus GetKeywordStringInput(String& inValue);
};

#endif // !defined(AFX_ENGINE_H__273FFF1E_D2B4_40D4_928D_E121ED833341__INCLUDED_)



